unit unLoginForm;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, LoginInterface, CnAAFont, CnAACtrls, StdCtrls, ExtCtrls, BusinessLogicInterface,
  cxGraphics, cxControls, cxLookAndFeels, cxLookAndFeelPainters, cxContainer,
  cxEdit, dxSkinsCore, dxSkinsDefaultPainters, Menus, cxButtons, cxTextEdit,
  cxMaskEdit, cxDropDownEdit, dxSkinsForm, dxSkinOffice2007Black,
  dxSkinOffice2007Blue, dxSkinOffice2007Green, dxSkinOffice2007Pink,
  dxSkinOffice2007Silver, ActnList, DB, ADODB, dxSkinBlack, dxSkinBlue,
  dxSkinCaramel, dxSkinCoffee, dxSkinDarkRoom, dxSkinDarkSide, dxSkinFoggy,
  dxSkinGlassOceans, dxSkiniMaginary, dxSkinLilian, dxSkinLiquidSky,
  dxSkinLondonLiquidSky, dxSkinMcSkin, dxSkinMoneyTwins, dxSkinPumpkin,
  dxSkinSeven, dxSkinSharp, dxSkinSilver, dxSkinSpringTime, dxSkinStardust,
  dxSkinSummer2008, dxSkinValentine, dxSkinXmas2008Blue;

type
  TLoginForm = class(TForm, ILoginForm)
    labUserName: TCnAALabel;
    labPassword: TCnAALabel;
    labInfo: TCnAALabel;
    btnLogin: TcxButton;
    btnQuit: TcxButton;
    edtPassword: TcxTextEdit;
    comUserName: TcxComboBox;
    ActionList: TActionList;
    SYSLogin: TAction;
    SYSQuit: TAction;
    QRY: TADOQuery;
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure SYSLoginExecute(Sender: TObject);
    procedure SYSQuitExecute(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
  private
    { Private declarations }
    FInfo:TStrings;
    bLoginState:boolean;
  public
    { Public declarations }
  public
    {interface : ILoginForm}
    function ShowLoginForm:boolean;
  end;

implementation

{$R *.dfm}

{ TLoginForm }

procedure TLoginForm.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  if not bLoginState then
  begin
    SYSParam.AddSYSParam('USER_LOGINSTATE','QUIT');
  end;
end;

procedure TLoginForm.FormCreate(Sender: TObject);
begin
  Top:=trunc(screen.DesktopHeight / 2)-trunc(self.Height / 2);
  Left:=trunc(screen.DesktopWidth / 2)-trunc(self.Width / 2);

  FInfo:=TStringList.Create;
  bLoginState:=False;

  QRY.Connection:=TADOConnection(SYSDB.GetDBConnection);
  QRY.SQL.Add('exec UserLogin :user,:pwd');
end;

procedure TLoginForm.FormDestroy(Sender: TObject);
begin
  FreeAndNil(FInfo);
end;

function TLoginForm.ShowLoginForm: boolean;
begin
  BringToFront;
  ShowModal;
  result:=bLoginState;
end;

procedure TLoginForm.SYSLoginExecute(Sender: TObject);
begin
  QRY.Close;
  QRY.Parameters.ParamByName('user').Value:=comUserName.Text;
  QRY.Parameters.ParamByName('pwd').Value:=edtPassword.Text;
  QRY.Open;
  while not QRY.Eof do
  begin
    SYSParam.AddSYSParam(QRY.FieldByName('ParamName').AsString,QRY.FieldByName('ParamValue').AsString);
    QRY.Next;
  end;
  if SYSParam.GetSYSParam('USER_LOGINSTATE')<>'SUCCESS' then
    bLoginState:=False
  else
    bLoginState:=True;

  Close;
end;

procedure TLoginForm.SYSQuitExecute(Sender: TObject);
begin
  SYSParam.AddSYSParam('USER_LOGINSTATE','QUIT');
  bLoginState:=False;
  Close;
end;

end.
